package com.fastfood.model.blo;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.fastfood.model.dao.FoodTypeDAO;
import com.fastfood.model.dto.FoodType;
import com.fastfood.util.DBConnectionPool;

public class FoodTypeBLO {

	private FoodTypeDAO dao = new FoodTypeDAO();
	
	public List<FoodType> getAllFoodTypes() {
		List<FoodType> foodTypes = null;
		Connection conn = DBConnectionPool.getConnectionPool().getConnection();
		if (conn != null) {
			foodTypes = dao.getAllFoodTypes(conn);
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return foodTypes;
	}
	
	public boolean addFoodType(FoodType foodType) {
		boolean result = false;
		Connection conn = DBConnectionPool.getConnectionPool().getConnection();
		if (conn != null) {
			result = dao.addFoodType(conn, foodType);
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return result;
	}
	
	public boolean updateFoodType(FoodType foodType) {
		boolean result = false;
		Connection conn = DBConnectionPool.getConnectionPool().getConnection();
		if (conn != null) {
			result = dao.updateFoodType(conn, foodType);
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return result;
	}
	
	public boolean deleteFoodType(FoodType foodType) {
		boolean result = false;
		Connection conn = DBConnectionPool.getConnectionPool().getConnection();
		if (conn != null) {
			result = dao.deleteFoodType(conn, foodType);
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return result;
	}
}
